home *** CD-ROM | disk | FTP | other *** search
- Path: gail.ripco.com!mambuhl
- From: mambuhl@ripco.com (Martin Ambuhl)
- Newsgroups: comp.lang.c
- Subject: returning ptr to struct w
- Date: 23 Feb 1996 18:49:34 GMT
- Organization: Ripco Communications, Inc.
- Message-ID: <4gl27u$dh3@gail.ripco.com>
- NNTP-Posting-Host: foley.ripco.com
-
- lbona@saratoga (lbona)
- in <4gk852INNbp4@faatcrl.faa.gov> writes:
-
-
- >When I declare a function that returns a pointer to a struct that contains
- >pointers, the pointer(s) at the end of the struct get set to garbage after
- >being returned. Pointers not at the end are not affected.
-
- [snip]
-
- >typedef struct bar {
- > long a;
- > long b;
- > int c;
- > AAA *d;
- > char e;
- > char f[100];
- > AAA *g;
- > AAA *h;
- >} BAR;
-
- >main()
- >{
- >BAR BB;
- >char toke[128];
-
- > memset(&BB,0,sizeof(BAR));
- > /* at this point BB.d == BB.g == BB.h == NULL */
-
- [snip]
-
- I apologize for not checking the rest of your code, but we need to stop
- and take stock here. While the contents BB.d, BB.g, and BB.h are all
- zero, there is _no_ guarantee that the null pointer (or floating point
- zero) have such a representation. If you depend on these being NULL,
- then you should set them explicitly.
-
-
- --
- * Martin Ambuhl net: mambuhl@ripco.com
- * Chicago, IL (USA)
-